package pt.nmfa.peste.session;

import pt.nmfa.peste.entity.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("tvProgramHome")
public class TvProgramHome extends EntityHome<TvProgram> {

	@In(create = true)
	ChannelsHome channelsHome;

	public void setTvProgramProgramId(Long id) {
		setId(id);
	}

	public Long getTvProgramProgramId() {
		return (Long) getId();
	}

	@Override
	protected TvProgram createInstance() {
		TvProgram tvProgram = new TvProgram();
		return tvProgram;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Channels channels = channelsHome.getDefinedInstance();
		if (channels != null) {
			getInstance().setChannels(channels);
		}
	}

	public boolean isWired() {
		if (getInstance().getChannels() == null)
			return false;
		return true;
	}

	public TvProgram getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
